package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WorkPhoto;
import com.ruoyi.system.service.IWorkPhotoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 照片表Controller
 * 
 * @author ruoyi
 * @date 2020-04-20
 */
@Controller
@RequestMapping("/system/photo")
public class WorkPhotoController extends BaseController
{
    private String prefix = "system/photo";

    @Autowired
    private IWorkPhotoService workPhotoService;

    //@RequiresPermissions("system:photo:view")
    @GetMapping()
    public String photo()
    {
        return prefix + "/photo";
    }

    /**
     * 查询照片表列表
     */
   // @RequiresPermissions("system:photo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WorkPhoto workPhoto)
    {
        startPage();
        List<WorkPhoto> list = workPhotoService.selectWorkPhotoList(workPhoto);
        return getDataTable(list);
    }

    /**
     * 导出照片表列表
     */
  //  @RequiresPermissions("system:photo:export")
    @Log(title = "照片表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WorkPhoto workPhoto)
    {
        List<WorkPhoto> list = workPhotoService.selectWorkPhotoList(workPhoto);
        ExcelUtil<WorkPhoto> util = new ExcelUtil<WorkPhoto>(WorkPhoto.class);
        return util.exportExcel(list, "photo");
    }

    /**
     * 新增照片表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存照片表
     */
   // @RequiresPermissions("system:photo:add")
    @Log(title = "照片表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WorkPhoto workPhoto)
    {
        return toAjax(workPhotoService.insertWorkPhoto(workPhoto));
    }

    /**
     * 修改照片表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WorkPhoto workPhoto = workPhotoService.selectWorkPhotoById(id);
        mmap.put("workPhoto", workPhoto);
        return prefix + "/edit";
    }

    /**
     * 修改保存照片表
     */
   // @RequiresPermissions("system:photo:edit")
    @Log(title = "照片表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WorkPhoto workPhoto)
    {
        return toAjax(workPhotoService.updateWorkPhoto(workPhoto));
    }

    /**
     * 删除照片表
     */
   // @RequiresPermissions("system:photo:remove")
    @Log(title = "照片表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(workPhotoService.deleteWorkPhotoByIds(ids));
    }
}
